<html>
<head><meta charset="utf-8"><title>double mutable linked list traversal · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html">double mutable linked list traversal</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="147674336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147674336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147674336">(Nov 14 2018 at 15:05)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="cp">#[derive(Debug, Clone)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Node</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">elem</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">next</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">Node</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">example</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">Node</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Skip forward 2 nodes</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">while</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">node</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="n">list</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="c1">// Skip forward 2 nodes</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">while</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">node</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="n">list</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>error[E0499]: cannot borrow `leading.next` as mutable more than once at a time
  --&gt; src/lib.rs:43:28
   |
28 |     while let Some(node) = &amp;mut leading.next {
   |                            ----------------- first mutable borrow occurs here
...
43 |     while let Some(node) = &amp;mut leading.next {
   |                            ^^^^^^^^^^^^^^^^^
   |                            |
   |                            second mutable borrow occurs here
   |                            first borrow used here, in later iteration of loop
</pre></div>



<a name="147674538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147674538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147674538">(Nov 14 2018 at 15:06)</a>:</h4>
<p>What am I missing here? The first loop works fine, but the second loop causes the error</p>



<a name="147677678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677678">(Nov 14 2018 at 15:38)</a>:</h4>
<p><span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> / <span class="user-mention" data-user-id="116009">@nikomatsakis</span> Is this code relevant to your loop diagnostic discussion?</p>



<a name="147677739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677739">(Nov 14 2018 at 15:39)</a>:</h4>
<p>I don't think it's relevant</p>



<a name="147677741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677741">(Nov 14 2018 at 15:39)</a>:</h4>
<p>the error is curious</p>



<a name="147677766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677766">(Nov 14 2018 at 15:39)</a>:</h4>
<p>Ok, cause this also has " in later iteration of loop", so your discussion caught my eye</p>



<a name="147677768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677768">(Nov 14 2018 at 15:39)</a>:</h4>
<p>trying to decide if it's a bug :)</p>



<a name="147677773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677773">(Nov 14 2018 at 15:39)</a>:</h4>
<p>yes, indeed</p>



<a name="147677783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677783">(Nov 14 2018 at 15:39)</a>:</h4>
<p>it might be, not entirely sure</p>



<a name="147677853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677853">(Nov 14 2018 at 15:40)</a>:</h4>
<p>and it's two distinct loops (shrug)</p>



<a name="147677901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677901">(Nov 14 2018 at 15:40)</a>:</h4>
<p>I think it might just be another instance of <a href="https://github.com/rust-lang/rust/issues/47680" target="_blank" title="https://github.com/rust-lang/rust/issues/47680">https://github.com/rust-lang/rust/issues/47680</a></p>



<a name="147677913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677913">(Nov 14 2018 at 15:41)</a>:</h4>
<p>the reasoning feels similar</p>



<a name="147677923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677923">(Nov 14 2018 at 15:41)</a>:</h4>
<p>basically, in one case, the borrow ends because no data</p>



<a name="147677930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677930">(Nov 14 2018 at 15:41)</a>:</h4>
<p>in the other branch (when <code>i==2</code> is false) the variable is overwritten</p>



<a name="147677936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677936">(Nov 14 2018 at 15:41)</a>:</h4>
<p>this is basically "the case" that polonius aims to fix</p>



<a name="147677952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677952">(Nov 14 2018 at 15:41)</a>:</h4>
<p>well, this plus "Problem Case <a href="https://github.com/rust-lang/rust/issues/3" target="_blank" title="https://github.com/rust-lang/rust/issues/3">#3</a>" from the original NLL RFC</p>



<a name="147677962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147677962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147677962">(Nov 14 2018 at 15:41)</a>:</h4>
<p>we should call this Problem Case <a href="https://github.com/rust-lang/rust/issues/4" target="_blank" title="https://github.com/rust-lang/rust/issues/4">#4</a> =)</p>



<a name="147678181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147678181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147678181">(Nov 14 2018 at 15:44)</a>:</h4>
<p>Oh, problem <a href="https://github.com/rust-lang/rust/issues/4" target="_blank" title="https://github.com/rust-lang/rust/issues/4">#4</a></p>



<a name="147678257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147678257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147678257">(Nov 14 2018 at 15:45)</a>:</h4>
<p>Yeah, to me <a href="https://github.com/rust-lang/rust/issues/3" target="_blank" title="https://github.com/rust-lang/rust/issues/3">#3</a> is all about cross-function interaction of borrows, but I don't see any function calls here.</p>



<a name="147678377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147678377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147678377">(Nov 14 2018 at 15:47)</a>:</h4>
<p>Reduced</p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Node</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">next</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">Box</span><span class="o">&lt;</span><span class="n">Node</span><span class="o">&gt;&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">example</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">Node</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">node</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">list</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">node</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">list</span><span class="p">.</span><span class="n">next</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">list</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">node</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>error[E0499]: cannot borrow `list.next` as mutable more than once at a time
  --&gt; src/lib.rs:10:25
   |
5  | fn example(mut list: &amp;mut Node) {
   |                      - let&#39;s call the lifetime of this reference `&#39;1`
6  |     if let Some(node) = &amp;mut list.next {
   |                 ----    -------------- first mutable borrow occurs here
   |                 |
   |                 assignment requires that `list.next` is borrowed for `&#39;1`
...
10 |     if let Some(node) = &amp;mut list.next {
   |                         ^^^^^^^^^^^^^^ second mutable borrow occurs here
</pre></div>



<a name="147678511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147678511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147678511">(Nov 14 2018 at 15:49)</a>:</h4>
<p>Do you think I should add these to that issue, or create a new one and cross-link them? If it is problem <a href="https://github.com/rust-lang/rust/issues/4" target="_blank" title="https://github.com/rust-lang/rust/issues/4">#4</a>, then a separate issue seems appropriate</p>



<a name="147684161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147684161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147684161">(Nov 14 2018 at 17:09)</a>:</h4>
<p>I'm not sure if you and I mean the same things by 3 and 4 =)</p>



<a name="147684164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147684164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147684164">(Nov 14 2018 at 17:09)</a>:</h4>
<p>I agree this has nothing to do with Problem Case <a href="https://github.com/rust-lang/rust/issues/3" target="_blank" title="https://github.com/rust-lang/rust/issues/3">#3</a>, which is all about returning something from the fn</p>



<a name="147684174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147684174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147684174">(Nov 14 2018 at 17:09)</a>:</h4>
<p>but I think it is the same as <a href="https://github.com/rust-lang/rust/issues/47680" target="_blank" title="https://github.com/rust-lang/rust/issues/47680">#47680</a>, which (unless I am forgetting something) also had nothing to do with returning things</p>



<a name="147684182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147684182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147684182">(Nov 14 2018 at 17:09)</a>:</h4>
<p>I think i'd prefer a comment  on <a href="https://github.com/rust-lang/rust/issues/47680" target="_blank" title="https://github.com/rust-lang/rust/issues/47680">#47680</a></p>



<a name="147684185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147684185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147684185">(Nov 14 2018 at 17:10)</a>:</h4>
<p>but a new issue is also ok, as long as the two are interlinked</p>



<a name="147691854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147691854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147691854">(Nov 14 2018 at 19:11)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> <a href="https://github.com/rust-lang/rust/issues/47680" target="_blank" title="https://github.com/rust-lang/rust/issues/47680">#47680</a> has all sorts of borrows optionally crossing function boundaries:</p>
<ul>
<li><code>fn get_child(&amp;mut self, value: char) -&gt; Option&lt;&amp;mut Self&gt;</code></li>
<li><code>fn get_self(&amp;mut self) -&gt; Option&lt;&amp;mut Self&gt;</code></li>
<li><code>fn maybe_next(&amp;mut self) -&gt; Option&lt;&amp;mut Self&gt;</code></li>
</ul>
<p>The linked list example here has no function calls at all. </p>
<p>To me, NLL <a href="https://github.com/rust-lang/rust/issues/3" target="_blank" title="https://github.com/rust-lang/rust/issues/3">#3</a> is "borrow checker understands when function <em>maybe</em> returns a borrow". I don't know what NLL#4 would be yet, but it certainly seems distinct from this.</p>



<a name="147692050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/double%20mutable%20linked%20list%20traversal/near/147692050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/double.20mutable.20linked.20list.20traversal.html#147692050">(Nov 14 2018 at 19:14)</a>:</h4>
<p>oh wait <a href="https://github.com/rust-lang/rust/issues/47680" target="_blank" title="https://github.com/rust-lang/rust/issues/47680">#47680</a>... is the opposite?</p>
<blockquote>
<p>The mutable borrow is released when matching on a Option&lt;&amp;mut Self&gt; in a function, but not when the function is inlined</p>
</blockquote>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>